
#include "CommonListener.h"
#include <boost/bind.hpp>

struct CommonListener::Impl{

    Impl(){
           }
    ~Impl(){
    }
};

CommonListener* CommonListener::inst = 0;
CommonListener *CommonListener::instance(){
    if ( inst) return inst;
    return inst = new CommonListener();
}

CommonListener::CommonListener():
    impl_(new Impl)
{
}
CommonListener::~CommonListener()
{

    delete impl_;
}
bool CommonListener::dispatch( ClientHost* host, const std::string & msg){
	std::cout<<"in dispatch"<<std::endl;
	std::cout<<msg<<std::endl;
	return false;
}
HostCallback CommonListener::getCallback(){
	return boost::bind( &CommonListener::dispatch, this, _1, _2);
}

#ifdef UNIT_TEST
#ifdef COMMONLISTENER_TEST
int main(){
    std::cout<<"CommonListener ok!"<<std::endl;

    TcpServer::instance()->startThread();
	TcpServer::instance()->addBasicListener(CommonListener::instance()->getCallback());
	std::cout<<"addBasicListener"<<std::endl;
	TcpServer::instance()->startAccept();
	std::cout<<"startAccept"<<std::endl;
    while(true){
        TcpServer::instance()->runMain();
    }

    std::cout<<"done"<<std::endl;
}
#endif
#endif
